import { FormProps, FormSchema } from '/@/components/Table';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { uploadApi } from '/@/api/sys/upload';
import {h} from "vue";
import {Tag} from "ant-design-vue";
import {Tinymce} from "/@/components/Tinymce";



//表格显示列
export function getBasicColumns(): BasicColumn[] {
  // @ts-ignore
  return [
    {
      title: 'ID',
      dataIndex: 'unitId',
      fixed: 'left',
      width: 100,
    },
    {
      title: '单位名称',
      dataIndex: 'unitName',
      width: 150,

    },
    {
      title: '单位简介',
      dataIndex: 'unitBrief',
      width: 100,
    },
    {
      title: '排序',
      width: 100,
      dataIndex: 'indexOrder',
    },

  ];
}

export function getFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 150,
    baseColProps: { lg: 6, md: 24 },
    schemas: formParamSchema,
  };
}


//编辑表单
export const formParamSchema: FormSchema[] = [
  {
    field: 'unitName',
    label: '单位名称',
    component: 'Input',
  },
];

//编辑表单
export const formSchema: FormSchema[] = [
  {
    field: 'unitName',
    label: '单位名称',
    component: 'Input',
    required: true,
  },

  {
    field: 'unitBrief',
    label: '单位简介',
    component: 'InputTextArea',
    required: true,
  },
  {
    field: 'indexOrder',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },
  {
    field: 'unitLogo',
    label: 'logo',
    component: 'Upload',
    componentProps: {
      api: uploadApi,
      accept: ['jpg', 'png', 'jpeg'],
      maxNumber: 1,
      maxSize: 1,
      helpText: '请上传png/jpg 等图片文件，文件大小小于1M,图片比例为4：1,合作伙伴为5：2',
    },
  },
  {
    field: 'coverImage',
    label: '单位展示图',
    component: 'Upload',
    componentProps: {
      api: uploadApi,
      accept: ['jpg', 'png', 'jpeg'],
      maxNumber: 1,
      maxSize: 1,
      helpText: '请上传png/jpg 等图片文件，文件大小小于1M,图片比例为4：1,合作伙伴为5：2',
    },
  },
  {
    field: 'unitDesc',
    component: 'Input',
    label: '单位详情',
    defaultValue: '',
    rules: [{required: true}],
    render: ({model, field}) => {
      return h(Tinymce, {
        value: model[field],
        onChange: (value: string) => {
          model[field] = value;
        },
      });
    },
  },
];
